import 'package:cached_network_image/cached_network_image.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBFindModel/YBFindModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBFindModule/YBFindSubPage/YBFindHeaderPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBAPi/YBAPi.dart';


class YBNewFindSubPage extends StatelessWidget {


  final YBFindModel findModel;

  const YBNewFindSubPage({Key key, this.findModel}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget widgetContainer;
    if (!ObjectUtil.isEmptyString(findModel.showType)) {
      if (findModel.showType.contains("yijiwang") || findModel.showType.contains("jinrilvsi") || findModel.showType.contains('lvsicha')) {
          widgetContainer = Container(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Container(
                  child: Padding(
                    padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize12,bottom:YBTextStyle.adapterSize12),
                    child: Text(
                      findModel.title??"",
                      style: TextStyle(
                        color: YBColor.color303133,
                        fontWeight: FontWeight.w600,
                        fontSize: YBTextStyle.adapterSize16,
                      ),
                    ),
                  ),
                ),
                Container(
                  child: Padding(
                    padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,bottom:YBTextStyle.adapterSize16),
                    child: Text(
                      findModel.content??"",
                      maxLines: 2,
                      style: TextStyle(
                        color: YBColor.color646464,
                        fontSize: YBTextStyle.adapterSize14,
                        fontWeight: FontWeight.w300,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          );
      }else if (findModel.showType.contains('kmt')) {
          String imagePreFixStr;
          if (findModel.imageUrl.startsWith("http://") || findModel.imageUrl.startsWith('https://')) {
              imagePreFixStr = findModel.imageUrl;
          }else{
            imagePreFixStr = '${YBApi.Base_image_URL}/$imagePreFixStr';
          }
          widgetContainer = Container(
            child: Padding(
              padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,bottom: YBTextStyle.adapterSize12,top:YBTextStyle.adapterSize12),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                    child: Padding(
                      padding: EdgeInsets.zero,
                      child: Text(
                        findModel.title??"",
                        style: TextStyle(
                          color: YBColor.color303133,
                          fontWeight: FontWeight.w500,
                          fontSize: YBTextStyle.adapterSize15
                        ),
                      ),
                    ),
                  ),
                  Container(
                    width: YBTextStyle.adapterSize112,
                    height: YBTextStyle.adapterSize77,
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(YBTextStyle.adapterSize8),
                      child: CachedNetworkImage(imageUrl:'${YBApi.Base_image_URL}/${findModel.imageUrl}'??"",fit: BoxFit.fitHeight,),
                    ),
                  ),
                ],
              ),
            ),
          );
      } else if (findModel.showType.contains('benlaiyoushu')) {
          widgetContainer = Container(
          child: Column(
            children: [
              Container(
                child: Padding(
                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize12,bottom: YBTextStyle.adapterSize12),
                  child: Text(
                    findModel.title??"",
                    style: TextStyle(
                        color: YBColor.color303133,
                        fontWeight: FontWeight.w500,
                        fontSize: YBTextStyle.adapterSize15
                    ),
                  ),
                ),
              ),
              Container(
                child: Padding(
                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,bottom:YBTextStyle.adapterSize16),
                  child: ClipRRect(
                     borderRadius: BorderRadius.circular(YBTextStyle.adapterSize16),
                     child: CachedNetworkImage(
                       imageUrl: '${YBApi.Base_image_URL}/${findModel.imageUrl}'??"",
                     ),
                  ),
                ),
              ),
            ],
          ),
        );
      }else if (findModel.showType.contains('lvdouxinyong')){
          widgetContainer = Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                child: Padding(
                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize16,bottom: YBTextStyle.adapterSize16),
                  child: Text(
                    findModel.title??"",
                    style: TextStyle(
                        color: YBColor.color303133,
                        fontWeight: FontWeight.w500,
                        fontSize: YBTextStyle.adapterSize15
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      } else if (findModel.showType.contains('圈层')) {
          widgetContainer = Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                child: Padding(
                  padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize12,bottom: YBTextStyle.adapterSize12),
                  child: Text(
                    findModel.title??"",
                    style: TextStyle(
                        color: YBColor.color303133,
                        fontWeight: FontWeight.w500,
                        fontSize: YBTextStyle.adapterSize15
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      }
    }  

    return Container(
       color: YBColor.white,
       child: InkWell(
         child: Column(
           children: [
             Container(
               child: YBFindHeaderPage(headerStr: findModel.headUrl,puslishUserName:findModel.publishUserName,publishTimeStr: findModel.publishTime,showTypeStr: findModel.showType,),
             ),
             Container(
               child: widgetContainer,
             ),
             Container(
               color: YBColor.colorF5F5F7,
               height:YBTextStyle.adapterSize8,
             ),
           ],
         ),
         onTap: () async {
           if (findModel.showType.contains('圈层')) {

           }else{
             YBApplication.router.navigateTo(context,
                 '/findQuanCengPage/findQuanCengDetailPage?ids=${findModel.id.toString()}');
           }
         },
       ),
    );
  }
}
